%{
#include <string>
#include <math.h>
#include "node.h"
#include "parser.hpp"
#define SAVE_TOKEN yylval.string = new std::string(yytext, yyleng);
#define TOKEN(t) (yylval.token = t)
extern "C" int yywrap() { }
%}


%x comment print

%%

"/*"					BEGIN(comment); /*printf("Begin comment");*/
<comment>[^*\n]*		;/*printf("%s", yytext);/* eat anything that's not a '*' */
<comment>"*"+[^\*\/\n]* ;/*printf("%s", yytext);/* eat up '*'s not followed by '/'s */
<comment>"*"+"/"		BEGIN(INITIAL); /*printf("End comment\n");*/

"printf"				{ printf("bbqp\n");SAVE_TOKEN; BEGIN(print); return TPRINT; }
<print>"[a-zA-Z0-9_]*"  { printf("bbqi\n"); return TIDENTIFIER; }
<print>"("              { printf("bbql\n"); return TOKEN(TLPAREN); }
<print>"\""				{ printf("bbqd\n"); return TOKEN(TQUOTA); }
<print>")"              { printf("bbqr\n"); BEGIN(INITIAL); return TOKEN(TRPAREN); }
[ \t\n]                 ;
"int"					{ SAVE_TOKEN; return TINT; }
"float"					{ SAVE_TOKEN; return TFLOAT; }
"void"					{ SAVE_TOKEN; return TVOID; }
"extern"                { return TOKEN(TEXTERN); }
"else if"				{ SAVE_TOKEN; return TELSEIF; }
"else"					{ SAVE_TOKEN; return TELSE; }
"for"					{ SAVE_TOKEN; return TFOR; }
"while"					{ SAVE_TOKEN; return TWHILE; }
"if"					{ SAVE_TOKEN; return TIF; }
"True"					{ SAVE_TOKEN; return TTRUE; }
"False"					{ SAVE_TOKEN; return TFALSE; }
"return"				{ SAVE_TOKEN; return TRETURN; }
[a-zA-Z_][a-zA-Z0-9_]*  { SAVE_TOKEN; return TIDENTIFIER; }
-?[0-9]+                { SAVE_TOKEN; return TINTEGER; }
-?[0-9]+\.[0-9]*        { SAVE_TOKEN; return TDOUBLE; }
"="                     { return TOKEN(TEQUAL); }
"=="                    { return TOKEN(TCEQ); }
"!="                    { return TOKEN(TCNE); }
"<"                     { return TOKEN(TCLT); }
"<="                    { return TOKEN(TCLE); }
">"                     { return TOKEN(TCGT); }
">="                    { return TOKEN(TCGE); }
"("                     { return TOKEN(TLPAREN); }
")"                     { return TOKEN(TRPAREN); }
"{"                     { return TOKEN(TLBRACE); }
"}"                     { return TOKEN(TRBRACE); }
"."                     { return TOKEN(TDOT); }
","                     { return TOKEN(TCOMMA); }
"\""					{ return TOKEN(TQUOTA);}
-?"+"                   { return TOKEN(TPLUS); }
-?"++"					{ return TOKEN(TPPLUS); }
-?"-"                   { return TOKEN(TMINUS); }
-?"--"					{ return TOKEN(TMMINUS); }
"*"                     { return TOKEN(TMUL); }
"/"                     { return TOKEN(TDIV); }
"&&"					{ return TOKEN(TAND); }
"||"					{ return TOKEN(TOR); }
";"						;
.                       printf("Unknown token!\n"); yyterminate();

%%
// void updateLocation(location_type *yylloc, int width) {
//     updateBegin(yylloc, 0);
//     updateEnd(yylloc, width);
// }